package com.sxran.im.handler;

import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxran.im.bean.NotificationBody;
import com.sxran.im.dao.ImChatBodyMapper;
import com.sxran.im.dao.ImNotificationMapper;
import com.sxran.im.info.ImChatBody;
import com.sxran.im.info.ImFriendInvite;
import com.sxran.im.info.ImNotification;
import com.sxran.im.info.ImUser;
import com.sxran.im.service.NotificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
@Service
public class NotificationAfterCmdHandler extends AbstractCmdHandler<NotificationBody>{
    @Resource
    private NotificationService notificationService;

    @Override
    public Object doBeanService(NotificationBody json) {
        // 存表....
        ImNotification imNotification = new ImNotification();
        imNotification.setType(json.getType());
        imNotification.setUuid(json.getUuid());
        imNotification.setIsRead(0);
        ImUser from = json.getFrom();
        imNotification.setFromUid(from.getUserId());
        imNotification.setFromInfo(JSONObject.toJSONString(from));
        imNotification.setToId(ArrayUtil.get(json.getTargetList(),0)  );
        imNotification.setServiceCreateTime(new Date(json.getServiceCreateTime()));
        imNotification.setContent(json.getContent().toString());
        notificationService.updateOrInsert(imNotification);
        return json;
    }



}
